package
{
	import com.vcar.LDiceClient.config.GlobalEventName;
	import com.vcar.LDiceClient.config.MediatorName;
	import com.vcar.LDiceClient.config.ProxyNames;
	import com.vcar.LDiceClient.dataproxy.RequestMessage;
	import com.vcar.LDiceClient.dataproxy.ResponseMessage;
	import com.vcar.LDiceClient.dataproxy.SocketProxy;
	
	import flash.display.DisplayObject;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import mx.core.Container;
	import mx.events.ResizeEvent;
	import mx.modules.ModuleLoader;
	
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.mediator.Mediator;
	
	/**
	 * 主应用的中介类 
	 * @author rhj
	 * 
	 */
	public class LDiceMediator extends Mediator
	{
		public function LDiceMediator(viewComponent:Object=null)
		{
			super(MediatorName.LDiceClient, viewComponent);
			app.debugBtn.addEventListener(MouseEvent.CLICK,debug);
			
		}
		
		/**
		 *
		 * 实现项目时加载对应的module
		 */		
		public function initModule():void
		{
		}
		
		override public function listNotificationInterests():Array
		{
			return [GlobalEventName.APP_LOGIN_SUCC];
		}
		
		override public function handleNotification(notification:INotification):void
		{
			var obj:ResponseMessage=notification.getBody() as ResponseMessage;
			switch (notification.getName())
			{
				case GlobalEventName.APP_LOGIN_SUCC://登录成功
				{
					chatPanel().visible=true;
				}
				break;
			}
		}
		
		/**
		 * 得到强类型的视图 
		 * @return 主应用
		 * @see 
		 */		
		public function get app():LDice
		{
			return viewComponent as LDice;
		}
		
		public function get mainModule():ModuleLoader
		{
			return app.main;
		}
		
		public function chatPanel():DisplayObject
		{
			return app.chatFrame;
		}

		public function get popLayer():Container
		{
			return app.popLayer;
		}
		
		public function get moduleData():Object
		{
			return app.moduleData;
		}
		
		private function debug(e:Event=null):void
		{
			var reMessage:RequestMessage = new RequestMessage();
			var proxy:SocketProxy = facade.retrieveProxy(ProxyNames.SocketProxy) as SocketProxy;
			reMessage.type=int(app.sub1Txt.text);
			reMessage.subtype=int(app.sub2Txt.text);
			proxy.send(reMessage);
		}
		
	}
}